/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.edu.ifal.supermercadobarateiro.gui;

import br.edu.ifal.supermercadobarateiro.bd.BdFuncionario;
import br.edu.ifal.supermercadobarateiro.modelo.Funcionario;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Mikaely Anaeve
 */
public class FrmCadastroFuncionario extends javax.swing.JFrame {

    /**
     * Creates new form FrmCadastroFuncionario
     */
    public FrmCadastroFuncionario() {
        initComponents();
        setTitle("Cadastro Funcionario");
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        btnAlterar = new javax.swing.JButton();
        btnSalvar = new javax.swing.JButton();
        btnBuscar = new javax.swing.JButton();
        btnExcluir = new javax.swing.JButton();
        pnlDadosFuncionario1 = new javax.swing.JPanel();
        lblNome1 = new javax.swing.JLabel();
        txtNome1 = new javax.swing.JTextField();
        cmbSexo1 = new javax.swing.JComboBox();
        lblsexo1 = new javax.swing.JLabel();
        lblCep1 = new javax.swing.JLabel();
        lblNumDaResid = new javax.swing.JLabel();
        txtNumDaResid = new javax.swing.JTextField();
        lblEstado1 = new javax.swing.JLabel();
        cmbEstado1 = new javax.swing.JComboBox();
        lblCPF1 = new javax.swing.JLabel();
        lblDataNascimento1 = new javax.swing.JLabel();
        lblRua1 = new javax.swing.JLabel();
        txtRua = new javax.swing.JTextField();
        lblComplemento1 = new javax.swing.JLabel();
        txtComplemento1 = new javax.swing.JTextField();
        lblCidade1 = new javax.swing.JLabel();
        txtCidade1 = new javax.swing.JTextField();
        lblTelefone1 = new javax.swing.JLabel();
        lblEmail1 = new javax.swing.JLabel();
        txtEmail1 = new javax.swing.JTextField();
        lblRg = new javax.swing.JLabel();
        txtRg = new javax.swing.JTextField();
        lblMensage1 = new javax.swing.JLabel();
        lblAviso = new javax.swing.JLabel();
        lblCod = new javax.swing.JLabel();
        txtCod = new javax.swing.JTextField();
        txtTelefone1 = new javax.swing.JTextField();
        txtCep1 = new javax.swing.JTextField();
        txtCpf1 = new javax.swing.JTextField();
        lblSenha = new javax.swing.JLabel();
        txtSenha = new javax.swing.JTextField();
        txtDataNascimento = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        btnAlterar.setText("Alterar");
        btnAlterar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAlterarActionPerformed(evt);
            }
        });

        btnSalvar.setText("Salvar");
        btnSalvar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSalvarActionPerformed(evt);
            }
        });

        btnBuscar.setText("Buscar");
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        btnExcluir.setText("Excluir");
        btnExcluir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnExcluirActionPerformed(evt);
            }
        });

        pnlDadosFuncionario1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados do Funcionário", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 10))); // NOI18N
        pnlDadosFuncionario1.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N

        lblNome1.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N
        lblNome1.setText("Nome :");

        txtNome1.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N
        txtNome1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtNome1ActionPerformed(evt);
            }
        });

        cmbSexo1.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N
        cmbSexo1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "  ", "Masculino", "Feminino" }));

        lblsexo1.setText("Sexo :");

        lblCep1.setText("CEP :");

        lblNumDaResid.setText("NumDaResid:");

        txtNumDaResid.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N

        lblEstado1.setText("Estado :");

        cmbEstado1.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N
        cmbEstado1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "    ", "Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Destrito Federal", "Espirito Santo", "Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul", "Minas Gerais", "Paraíba", "Paraná", "Pará", "Pernambuco", "Piauí", "Sergipe", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Rondônia", "Roraima", "Santa Catarina", "São Paulo", "Tocantins" }));

        lblCPF1.setText("C.P.F :");

        lblDataNascimento1.setText("Data de Nascimento: ");

        lblRua1.setText("Rua  :");

        txtRua.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N

        lblComplemento1.setText("Complemento :");

        txtComplemento1.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N
        txtComplemento1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtComplemento1ActionPerformed(evt);
            }
        });

        lblCidade1.setText("Cidade :");

        txtCidade1.setFont(new java.awt.Font("Ubuntu", 0, 11)); // NOI18N

        lblTelefone1.setText("Telefone :");

        lblEmail1.setText("e-mail :");

        txtEmail1.setFont(new java.awt.Font("Comic Sans MS", 0, 11)); // NOI18N

        lblRg.setText("RG:");

        lblMensage1.setName("     "); // NOI18N

        lblCod.setText("Cod:");

        lblSenha.setText("Senha:");

        javax.swing.GroupLayout pnlDadosFuncionario1Layout = new javax.swing.GroupLayout(pnlDadosFuncionario1);
        pnlDadosFuncionario1.setLayout(pnlDadosFuncionario1Layout);
        pnlDadosFuncionario1Layout.setHorizontalGroup(
            pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addComponent(lblAviso, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                        .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                                .addComponent(lblCidade1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtCidade1))
                            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                                .addComponent(lblComplemento1, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtComplemento1, javax.swing.GroupLayout.PREFERRED_SIZE, 498, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                                .addComponent(lblTelefone1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtTelefone1, javax.swing.GroupLayout.PREFERRED_SIZE, 52, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblEmail1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtEmail1)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblMensage1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                        .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                                .addComponent(lblRua1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtRua, javax.swing.GroupLayout.PREFERRED_SIZE, 390, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblNumDaResid)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtNumDaResid, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                                .addComponent(lblRg)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(txtRg, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblCep1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(txtCep1, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(lblEstado1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(cmbEstado1, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(lblSenha)
                                .addGap(18, 18, 18)
                                .addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, 75, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlDadosFuncionario1Layout.createSequentialGroup()
                                        .addGap(1, 1, 1)
                                        .addComponent(lblNome1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtNome1, javax.swing.GroupLayout.PREFERRED_SIZE, 365, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(lblCod))
                                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, pnlDadosFuncionario1Layout.createSequentialGroup()
                                        .addComponent(lblCPF1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(txtCpf1, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(60, 60, 60)
                                        .addComponent(lblsexo1)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(cmbSexo1, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(lblDataNascimento1)))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtCod, javax.swing.GroupLayout.DEFAULT_SIZE, 70, Short.MAX_VALUE)
                                    .addComponent(txtDataNascimento))))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        pnlDadosFuncionario1Layout.setVerticalGroup(
            pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlDadosFuncionario1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblNome1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtNome1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(lblCod)
                        .addComponent(txtCod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblMensage1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE, false)
                    .addComponent(lblsexo1)
                    .addComponent(cmbSexo1)
                    .addComponent(lblDataNascimento1)
                    .addComponent(lblCPF1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(txtCpf1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(2, 2, 2)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblRg)
                    .addComponent(txtRg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblCep1)
                    .addComponent(lblEstado1, javax.swing.GroupLayout.PREFERRED_SIZE, 22, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(cmbEstado1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtCep1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblSenha)
                    .addComponent(txtSenha, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(5, 5, 5)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblCidade1)
                    .addComponent(txtCidade1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblRua1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtRua, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblNumDaResid)
                    .addComponent(txtNumDaResid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblComplemento1, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txtComplemento1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblTelefone1)
                        .addComponent(txtTelefone1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pnlDadosFuncionario1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblEmail1)
                        .addComponent(txtEmail1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblAviso, javax.swing.GroupLayout.DEFAULT_SIZE, 23, Short.MAX_VALUE)
                .addGap(34, 34, 34))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(pnlDadosFuncionario1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(btnBuscar)
                        .addGap(33, 33, 33)
                        .addComponent(btnSalvar)
                        .addGap(28, 28, 28)
                        .addComponent(btnAlterar)
                        .addGap(18, 18, 18)
                        .addComponent(btnExcluir)
                        .addGap(200, 200, 200))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(25, Short.MAX_VALUE)
                .addComponent(pnlDadosFuncionario1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(33, 33, 33)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnExcluir)
                    .addComponent(btnAlterar)
                    .addComponent(btnSalvar)
                    .addComponent(btnBuscar))
                .addGap(24, 24, 24))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed
        String srcid = txtCod.getText();
        int id = Integer.parseInt(srcid);
        Funcionario f = new Funcionario();
        f.setId(id);
        BdFuncionario cbd = new BdFuncionario();
        try {
            f = cbd.busca(id);

            if (f == null || f.getNome() == null) {
                lblAviso.setText("funcionario não existe.");

            } else {
                txtNome1.setText(f.getNome());
                //termina ai cada txt , vc tem que fazer praticamente o mesmo                
                lblAviso.setText("");
            }
        } catch (SQLException ex) {
            Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btnBuscarActionPerformed
    public void limparCampos() {
        txtNome1.setText("");
        txtEmail1.setText("");
        txtCep1.setText("");
        txtCpf1.setText("");
        txtComplemento1.setText("");
        txtCod.setText("");
        txtTelefone1.setText("");
        txtRua.setText("");
        txtRg.setText("");
        txtNumDaResid.setText("");
        txtCidade1.setText("");




        lblAviso.setText("");
    }
    private void txtNome1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtNome1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtNome1ActionPerformed

    private void txtComplemento1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtComplemento1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtComplemento1ActionPerformed

    private void btnAlterarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAlterarActionPerformed
        
        String srcNome= txtNome1.getText();
       
        String srcCidade= txtCidade1.getText();
        String srcEmail= txtEmail1.getText();
       
        //Preenche um objeto Contato com os dados do forumário.
        Funcionario f = new Funcionario();
        f.setNome(srcNome);
       /* f.setEmail(srcEmail);
        f.setTelefone(telefone);
        f.setCidade(srcCidade);
        f.setCep(cep);
        f.setCpf(cpf);
        */

        try {
            //Cria um objeto que conecta no BD.
            BdFuncionario cbd = new BdFuncionario();
            //Chama o método para atualizar contato no BD.
            cbd.altera(f);
            lblAviso.setText("Alterado com sucesso!");

        } catch (SQLException ex) {
            Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(Level.SEVERE, null, ex);
            lblAviso.setText("Não foi possível alterar");
        }
    }//GEN-LAST:event_btnAlterarActionPerformed

    private void btnSalvarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSalvarActionPerformed
         String srcNome= txtNome1.getText();
       /* String srcTelefone= txtTelefone1.getText();
        int telefone= Integer.parseInt(srcTelefone);*/
        String srcCidade= txtCidade1.getText();
        String srcEmail= txtEmail1.getText();
        /*String srcCep= txtCep1.getText();
        int cep= Integer.parseInt(srcCep);
        String srcCpf= txtCpf1.getText();
        int cpf= Integer.parseInt(srcCpf);*/
         String srcSenha= txtSenha.getText();
       Funcionario f = new Funcionario();
        f.setNome(srcNome);
        
        f.setCidade(srcCidade);
        f.setEmail(srcEmail);
        
        f.setSenha(srcSenha);
        try {
            BdFuncionario cbd = new BdFuncionario();
            cbd.insere(f);            
            limparCampos();
        } catch (SQLException ex) {
            Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(Level.SEVERE, null, ex);            
        }
    }//GEN-LAST:event_btnSalvarActionPerformed

    private void btnExcluirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnExcluirActionPerformed
        String srcId = txtCod.getText();
        int id = Integer.parseInt(srcId);
        Funcionario f = new Funcionario();
        f.setId(id);

        BdFuncionario fbd = new BdFuncionario();
        try {

            int resposta = JOptionPane.showConfirmDialog(null, "Deseja realmente excluir este funcionario?");
            if (resposta == JOptionPane.CANCEL_OPTION || resposta == JOptionPane.NO_OPTION) {                
            } else {
                fbd.remove(f);
                limparCampos();
            }
        } catch (SQLException ex) {
            Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(Level.SEVERE, null, ex);
            

        }
    }//GEN-LAST:event_btnExcluirActionPerformed
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmCadastroFuncionario.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FrmCadastroFuncionario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnAlterar;
    private javax.swing.JButton btnBuscar;
    private javax.swing.JButton btnExcluir;
    private javax.swing.JButton btnSalvar;
    private javax.swing.JComboBox cmbEstado1;
    private javax.swing.JComboBox cmbSexo1;
    private javax.swing.JLabel lblAviso;
    private javax.swing.JLabel lblCPF1;
    private javax.swing.JLabel lblCep1;
    private javax.swing.JLabel lblCidade1;
    private javax.swing.JLabel lblCod;
    private javax.swing.JLabel lblComplemento1;
    private javax.swing.JLabel lblDataNascimento1;
    private javax.swing.JLabel lblEmail1;
    private javax.swing.JLabel lblEstado1;
    private javax.swing.JLabel lblMensage1;
    private javax.swing.JLabel lblNome1;
    private javax.swing.JLabel lblNumDaResid;
    private javax.swing.JLabel lblRg;
    private javax.swing.JLabel lblRua1;
    private javax.swing.JLabel lblSenha;
    private javax.swing.JLabel lblTelefone1;
    private javax.swing.JLabel lblsexo1;
    private javax.swing.JPanel pnlDadosFuncionario1;
    private javax.swing.JTextField txtCep1;
    private javax.swing.JTextField txtCidade1;
    private javax.swing.JTextField txtCod;
    private javax.swing.JTextField txtComplemento1;
    private javax.swing.JTextField txtCpf1;
    private javax.swing.JTextField txtDataNascimento;
    private javax.swing.JTextField txtEmail1;
    private javax.swing.JTextField txtNome1;
    private javax.swing.JTextField txtNumDaResid;
    private javax.swing.JTextField txtRg;
    private javax.swing.JTextField txtRua;
    private javax.swing.JTextField txtSenha;
    private javax.swing.JTextField txtTelefone1;
    // End of variables declaration//GEN-END:variables
}
